package com.fangda.network.websocket.server;

import com.fangda.network.NetworkConfig;
import com.fangda.network.NetworkProvider;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.web.Router;

public class WebsocketServerProvider implements NetworkProvider<WebsocketServerNetwork> {
	
    @Override
    public WebsocketServerNetwork createNetwork(Vertx vertx, String id, NetworkConfig networkConfig) {
        HttpServerOptions config = (HttpServerOptions)networkConfig.getConfig().getOrDefault("options", new HttpServerOptions());
        Router router = Router.router(vertx);
        WebsocketServerNetwork network = new WebsocketServerNetwork(id, networkConfig);
        HttpServer httpServer = vertx.createHttpServer(config);
        network.setServer(httpServer);
        network.setRouter(router);
        return network;
    }
}
